package com.souku.finance.application.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.webkit.WebView;

/**
 * Created by Android on 2016/12/20.
 */

public class TouchWebView extends WebView {

    protected PullUpToLoadMore ptlm;

    public TouchWebView(Context context) {
        super(context);
    }

    public TouchWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TouchWebView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    float x1 = 0;
    float x2 = 0;
    float y1 = 0;
    float y2 = 0;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        //继承了Activity的onTouchEvent方法，直接监听点击事件
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            //当手指按下的时候
            x1 = event.getX();
            y1 = event.getY();
        }
        if (event.getAction() == MotionEvent.ACTION_UP) {
            //当手指离开的时候
            x2 = event.getX();
            y2 = event.getY();
            if (y1 - y2 > 100) {
            } else if (y2 - y1 > 150) {
                if (ptlm != null && getScrollY() == 0) {
                    ptlm.scrollToTop();
                }
            } else if (x1 - x2 > 100) {
            } else if (x2 - x1 > 100) {
            }
        }
        return super.onTouchEvent(event);
    }

    public PullUpToLoadMore getPtlm() {
        return ptlm;
    }

    public void setPtlm(PullUpToLoadMore ptlm) {
        this.ptlm = ptlm;
    }
}
